package com.yanyu.space.common.log.handler;

import com.yanyu.space.common.core.properties.LogProperties;
import com.yanyu.space.common.core.util.AppContext;
import com.yanyu.space.common.log.message.pool.LogMessagePool;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.cloud.sleuth.Tracer;
import org.springframework.context.EnvironmentAware;
import org.springframework.core.Ordered;
import org.springframework.core.env.Environment;

/**
 * @author yanyu
 */
@Slf4j
@AllArgsConstructor
public class LogBootstrap implements CommandLineRunner, Ordered {
    private LogProperties logProperties;

    @Override
    public void run(String... args) throws Exception {
        LogFactory.getInstance().init(
                logProperties.getProcessor().getConcurrency(),
                AppContext.getBean(Tracer.class),
                LogMessagePool.class);
    }

    @Override
    public int getOrder() {
        return Ordered.LOWEST_PRECEDENCE + 1;
    }
}
